package com.ssy.lingxi.product.entity.channelCommodity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.product.entity.Goods;
import com.ssy.lingxi.product.handler.converter.JpaJsonToMapConverter;
import lombok.Getter;
import lombok.Setter;

import javax.persistence.*;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * 商品实体类
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/28
 */
@Getter
@Setter
@Entity
@Table(schema = "public", name = "product_channel_commodity_unitPriceAndPic")
public class ChannelCommodityUnitPricePic implements Serializable {
    private static final long serialVersionUID = 2885874691455279090L;
    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy= GenerationType.SEQUENCE, generator="channel_commodity_unitPriceAndPic_seq")
    @SequenceGenerator(sequenceName="product_channel_commodity_unitPriceAndPic_seq", name="channel_commodity_unitPriceAndPic_seq",allocationSize = 1)
    private Long id;

    /**
     * 渠道会员
     */
    @JsonIgnore
    @ManyToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="channelCommodityMemberId",referencedColumnName = "id")
    private ChannelCommodityMember channelCommodityMember;

    /**
     * 货品
     */
    @OneToOne(cascade = {CascadeType.PERSIST})
    @JoinColumn(name="goodsId",referencedColumnName = "id")
    private Goods goods;

    /**
     * 渠道商品属性
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "channelCommodityUnitPricePic", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
    private List<ChannelCommodityAttribute> attributeAndValueList;

    /**
     * 渠道商品单价
     */
    @Convert(converter = JpaJsonToMapConverter.class)
    @Column(columnDefinition="jsonb", nullable = false)
    private Map<String,Double> unitPrice;

    /**
     * 会员商品价格id
     */
    @Column(columnDefinition = "int8")
    private Long commodityUnitPriceAndPicId;
}
